package memory;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class Memory {
	private HashMap<String, Integer> variables;
	
	static Set<Character> ciphers, letters;
	
	public Memory() {
		variables = new HashMap<String, Integer>();
		
		letters = new HashSet<Character>();
		for (char c = 'a'; c <= 'z'; c++) {
			letters.add(c);
		}
		for (char c = 'A'; c <= 'Z'; c++) {
			letters.add(c);
		}
		ciphers = new HashSet<Character>();
		for (char c = '0'; c <= '9'; c++) {
			ciphers.add(c);
		}
		
	}
	
	public void assign(String name, int value) {
		variables.put(name, value);
	}
	
	public int getValue(String name) {
		if (!variables.containsKey(name)) {
			variables.put(name, 0);
		}
		return variables.get(name);
	}
	
	static public boolean isCorrectVariableName(String name) {
		if (!letters.contains(name.charAt(0))) {
			return false;
		}
		for (int i = 0; i < name.length(); i++) {
			if (!letters.contains(name.charAt(i)) && !ciphers.contains(name.charAt(i))) {
				return false;
			}
		}
		return true;
	}
}
